package com.it.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/*
 * 业务层配置
 * 【说明】：
 *        1、service、aop注解：tx
 * */
@Configuration
@ComponentScan("com.it.service")
@EnableAspectJAutoProxy         // 开启 AOP 切面编程
@EnableTransactionManagement    // 开启 Tx 事务
public class ServiceConfig {
    // 指定事务管理器
    @Bean
    public DataSourceTransactionManager transactionManager(DataSource dataSource) {
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        transactionManager.setDataSource(dataSource);
        return transactionManager;
    }
}
